#!/bin/bash
# filename: dls
# description: list assets
# input: parent cid
# Toan Nguyen, June 2012

#     Copyright © 2012-2013 Toan Nguyen <toan.nguyen@monash.edu>
#
#     This file is part of Xglom.
# 
#     This is free software: you can redistribute it and/or modify
#     it under the terms of the GNU General Public License as published by
#     the Free Software Foundation, either version 3 of the License, or
#     (at your option) any later version.
# 
#     This is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU General Public License for more details.
# 
#     You should have received a copy of the GNU General Public License
#     along with this program.  If not, see <http://www.gnu.org/licenses/>.

# ========= MAIN SCRIPT ============
# check system
. dcheck

RECURSIVE_LEVEL=1
SIZE=500
UNIT_TYPE=1
DISPLAY_PROCESSED="false"
# 1: byte, 2: kb, 3: mb

while getopts hr:s:kmp OPTION
do
     case $OPTION in
         h) echo "Usage: dls [-h] [-r value] [-s value] [-k] [-m] [-p] cid"
            exit 1
            ;;

         r) RECURSIVE_LEVEL=$OPTARG
            ;;

	 k) UNIT_TYPE=2
            ;;

         m) UNIT_TYPE=3
            ;;

         s) SIZE=$OPTARG
            ;;
			
		 p) DISPLAY_PROCESSED="true"
			;;

         ?) echo "Usage: dls [-h] [-r value] [-s value] [-k] [-m] [-p] cid"
            exit 1
            ;;
     esac
done
shift $(($OPTIND - 1))
ASSET_CID=$1

# run service and display result
if [ -z $ASSET_CID ]; then
    $MFCOMMAND mbi.pssd.asset.summary :recursive-level $RECURSIVE_LEVEL :size $SIZE :unit $UNIT_TYPE :display-type ${DISPLAY_PROCESSED} | tr -d \"
else
    $MFCOMMAND mbi.pssd.asset.summary :id $ASSET_CID :recursive-level $RECURSIVE_LEVEL :size $SIZE :unit $UNIT_TYPE :display-type ${DISPLAY_PROCESSED} | tr -d \"
fi
